package com.me.videoservice.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.me.videoservice.model.common.Pageable;
import com.me.videoservice.model.entry.DeviceInfoWithStream;
import com.me.videoservice.model.entry.VideoPublishInfo;
import com.me.videoservice.service.VideoPublishService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/publish")
@CrossOrigin
public class VideoPublishController {

  @Resource
  private VideoPublishService videoPublishService;

  @GetMapping
  public R<List<DeviceInfoWithStream>> queryAll() {
    return new R<List<DeviceInfoWithStream>>().setData(videoPublishService.queryAll());
  }

  @PostMapping("page_query")
  public R<Page<VideoPublishInfo>> pageQuery(@RequestBody Pageable pageable) {
    return new R<Page<VideoPublishInfo>>().setData(
        videoPublishService
            .page(new Page<>(pageable.getPage(), pageable.getPageCount())));
  }
}
